chore: small consistency and documentation fixes#60
Conversation
- AnalyticsRules and CurationSets now memoize their resource proxies in `[]`, matching the pattern every other collection class already uses (Collections, Documents, Aliases, Keys, Presets, SynonymSets, etc). Calls like `client.curation_sets['x']` now return the same instance across calls, which is the documented contract elsewhere. - Remove an unreachable `|| 3` fallback from `Configuration#num_retries`: the LHS is always an integer because `validate!` rejects empty `nodes`. - Replace `node.send(:[], attr)` with `node[attr]` in `Configuration#node_missing_parameters?` — same behaviour, less indirection. - Document `Typesense::Error#data` in the README so callers know how to read the HTTP status and body from a raised exception.
|
Looks like some tests are failing |
| @connection_timeout_seconds = options[:connection_timeout_seconds] || options[:timeout_seconds] || 10 | ||
| @healthcheck_interval_seconds = options[:healthcheck_interval_seconds] || 15 | ||
| @num_retries = options[:num_retries] || (@nodes.length + (@nearest_node.nil? ? 0 : 1)) || 3 | ||
| @num_retries = options[:num_retries] || (@nodes.length + (@nearest_node.nil? ? 0 : 1)) |
There was a problem hiding this comment.
We do want the default num retries to b 3. Any reason this was removed?
There was a problem hiding this comment.
The || 3 here is effectively unreachable. (nodes.length + nearest_count) always returns a truthy Integer, and validate! ensures it’s ≥ 1 at runtime.
So the effective default is nodes.length + (nearest_node ? 1 : 0), which often ends up as 3 in typical setups.
Happy to switch to a flat 3, but that would change behavior for smaller clusters rather than restore it.
Added extra tests in configuration_spec.rb that pin down num_retries's default.
There was a problem hiding this comment.
Fixed this by enforcing a minimum of 3 via max:
Behavior:
- Explicit num_retries (including 0) → honored as-is
- 1 node, no nearest → 3 (was 1)
- 3 nodes, no nearest → 3
- 3 nodes + nearest → 4
Also updated the single-node spec from expecting 1 to expecting 3.
A handful of unrelated small fixes that don't really warrant individual PRs.
AnalyticsRules#[]andCurationSets#[]now memoizeEvery other resource collection in the gem caches its proxy on first
[]access —Collections,Documents,Aliases,Keys,Presets,Synonyms,SynonymSets,NlSearchModels,StemmingDictionaries,Overrides,CurationSetItems,AnalyticsRulesV1.AnalyticsRulesandCurationSetswere the only two that built a fresh wrapper on every call.This is purely a consistency fix — there was no shared mutable state on the proxies, so the previous behaviour wasn't a bug, just surprising.
Drop unreachable
|| 3fallback inConfiguration#num_retriesThe LHS is always a positive integer —
validate!raises before we get here if@nodesis empty — so|| 3can never fire. Just deletes the dead tail.Drop
node.send(:[], attr)innode_missing_parameters?Same behaviour, less indirection.
README: document
Typesense::Error#dataTypesense::Errorexposes a.datareader that holds the underlying Faraday response, but the README didn't mention it. Adds a short error-handling section showing how to pull the status / body off a raised exception, plus the list of status-code-to-class mappings.Tests
bundle exec rspec spec/typesense/configuration_spec.rb spec/typesense/analytics_rules_spec.rb spec/typesense/curation_sets_spec.rb— all green.bundle exec rubocopon the touched files — no offences.PR Checklist